package com.code;

import java.util.concurrent.*;

/**
 * @description:  实现Callable接口开启线程
 * @author: lwh
 * @date: Created in 2020/3/17 16:46
 * @modified By:
 */

public class ThreadDemo03 implements Callable<Boolean> {

    public ThreadDemo03() {
    }

    @Override
    public Boolean call() {

        for (int i = 0; i < 5; i++) {
            System.out.println("我是子线程"+i);
        }
        return true;
    }

    public static void main(String[] args) throws ExecutionException, InterruptedException {

        ThreadDemo03 thread = new ThreadDemo03();

//        创建服务
        ExecutorService es = Executors.newFixedThreadPool(3);

//        提交执行
        Future<Boolean> r1 = es.submit(thread);

//        获取结果
        boolean rs1 = r1.get();

        System.out.println(rs1);

//        关闭服务
        es.shutdown();


    }

}
